package com.handl.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
//开启服务注册和发现
@EnableDiscoveryClient
//开启断路器功能
@EnableHystrix
//开启断路器的仪表盘功能
@EnableHystrixDashboard
//开启支持集群服务仪表盘监控
@EnableTurbine
public class RibbonApplication {

	public static void main(String[] args) {
		SpringApplication.run(RibbonApplication.class, args);
	}

	/**
	 * RestTemplate是ribbon负载均衡的模板类，用来处理服务的调用
	 * LoadBalanced注解用来开启客户端负载均衡功能
	 * @return
	 */
	@Bean
	@LoadBalanced //开启负载均衡功能
	RestTemplate restTemplate(){
		return new RestTemplate();
	}
}
